#include <CoordinateAtCorner.h>
#include <SceneViewer.h>
#include <SceneViewerFunctions.h>
#include <osg/NodeCallback>
//#include <LuaFunctions.h>
class CoordinateCameraCallBack : public osg::NodeCallback
{
public:
	CoordinateCameraCallBack()
	{

	}
	virtual ~CoordinateCameraCallBack()
	{

	}
	virtual void operator() ( osg::Node *node, osg::NodeVisitor *nv)
	{
		CoordinateAtCorner* corner = dynamic_cast<CoordinateAtCorner*>(node);
		if (corner == NULL)
		{
			return;
		}
		osg::Matrix switch_m = SceneViewer::instance()->getSwitchCameraManipulator()->getMatrix();
		osg::Matrix m;

		//double trans_z = ;

		m.makeTranslate(0, 0, -5);
		m = osg::Matrix::inverse(osg::Matrix::rotate(switch_m.getRotate()))*m;

		corner->setViewMatrix(m);

	}
};
CoordinateAtCorner::CoordinateAtCorner()
{
	this->setViewMatrix(osg::Matrix::identity());
	this->setProjectionMatrix(osg::Matrix::identity() );
	this->setRenderOrder(osg::Camera::POST_RENDER);
	this->setClearMask(GL_DEPTH_BUFFER_BIT);
	this->setAllowEventFocus(false);
    this->setViewport(0, 0, 50, 50);
	osg::ref_ptr<osg::Node> gnode = SceneViewerFunctions::CreateCoordinate(0.8);
	this->addChild(gnode);

	this->setUpdateCallback(new CoordinateCameraCallBack);
	this->setReferenceFrame(osg::Transform::ReferenceFrame::ABSOLUTE_RF);
}

CoordinateAtCorner::~CoordinateAtCorner()
{

}
